package pl.wroc.uni.ii.puzzle.data;

import java.lang.reflect.Type;
import java.util.Date;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

public class DateDeserializer implements JsonDeserializer<Date>{

	@Override
	public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext ctx) throws JsonParseException {
		JsonElement jsonPrimitive = json.getAsJsonPrimitive();
		if (jsonPrimitive == null) {
			throw new JsonParseException("jsonPrimitive is null");
		}
		Long milis = Long.parseLong(jsonPrimitive.getAsString());
		return new Date(milis);
	}

}
